﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Coldairarrow.Util.ClassLibrary;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_StationController : BaseApiController
    {
        #region DI
        private readonly MongoDBOptions _mongodbOptions;
        public PB_StationController(IPB_StationBusiness pB_StationBus, IOptions<MongoDBOptions> mongodbOptions)
        {
            _pB_StationBus = pB_StationBus;
            _mongodbOptions = mongodbOptions.Value;
        }

        IPB_StationBusiness _pB_StationBus { get; }

        #endregion

        #region 获取 

        [HttpPost]
        public async Task<PageResult<PB_StationDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_StationBus.GetDataListAsync(input);
        }
        [HttpPost]
        public async Task<PageResult<PB_Station>> GetDataListByDepartment(string DeptId)
        {
            return await _pB_StationBus.GetDataListByDepartmentAsync(DeptId);
        }
        /// <summary>
        ///打印工位队列 
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AjaxResult> SelectStationID(string ID)
        {
            return await _pB_StationBus.SelectStationID(ID, _mongodbOptions);
        }
        [HttpPost]
        public async Task<PageResult<PB_Station>> GetDataListByWorkshop(string workshopId)
        {
            return await _pB_StationBus.GetDataListByWorkshopAsync(workshopId);
        }
       
        [HttpPost]
        public async Task<PB_Station> GetTheData(IdInputDTO input)
        {
            return await _pB_StationBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Station data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_StationBus.AddDataAsync(data);
            }
            else
            {
                await _pB_StationBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_StationBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}